/*
Copyright (C) 2004 Jacquelin POTIER <jacquelin.potier@free.fr>
Dynamic aspect ratio code Copyright (C) 2004 Jacquelin POTIER <jacquelin.potier@free.fr>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

//-----------------------------------------------------------------------------
// Object: generate COM auto monitoring files from type library files (.tlb)
//-----------------------------------------------------------------------------

#pragma once

#include <windows.h>
#include "../../../../Com/GUIDStringConvert.h"
#include "../../../../File/TextFile.h"
#include "../../../../File/StdFileOperations.h"
#include "../../../../Exception/HardwareException.h"
#include "../InterfaceInfo.h"


#define CCOMMonitoringFileGenerator_TYPE_LIB_KEY _T("TypeLib")
#define COM_INTERFACE_MONITORING_FILE_HEADER _T(";COM Interface Monitoring File generated by Monitoring File Builder\r\n;For syntax, see documentation, COM/Auto Monitoring Files Syntax\r\n\r\n")

class CCOMMonitoringFileGenerator
{
public:
    enum tagUserMessagesTypes
    {
        USER_MESSAGE_INFORMATION=0,
        USER_MESSAGE_WARNING,
        USER_MESSAGE_ERROR
    };

    typedef void (*tagUserMessageInformationCallBack)(TCHAR* Message,
                                                        tagUserMessagesTypes MessageType,
                                                        LPVOID UserParam);
    typedef void (*tagProgressCallBack)(BYTE PercentCompleted,LPVOID UserParam);


    CCOMMonitoringFileGenerator();
    CCOMMonitoringFileGenerator(tagProgressCallBack PercentCompletedCallBack,LPVOID PercentCompletedCallBackUserParam,tagUserMessageInformationCallBack UserMessageInformationCallBack,LPVOID UserMessageInformationCallBackUserParam);
    ~CCOMMonitoringFileGenerator(void);

    BOOL GenerateCOMAllRegisteredTypeLibrariesMonitoring(TCHAR* OutputDirectory,HANDLE hCancelEvent);
    BOOL GenerateCOMTypeLibraryMonitoring(TCHAR* TypeLibraryPath,TCHAR* OutputDirectory,HANDLE hCancelEvent);

private:
    BOOL bOperationCanceled;
    TCHAR CurrentTypeLibrary[MAX_PATH];
    tagProgressCallBack PercentCompletedCallBack;
    tagUserMessageInformationCallBack UserMessageInformationCallBack;
    LPVOID UserMessageInformationCallBackUserParam;
    LPVOID PercentCompletedCallBackUserParam;
    void UserMessage(TCHAR* ErrorMsg,tagUserMessagesTypes MessageType);
    void ReportProgress(BYTE PercentCompleted);
    BOOL GenerateCOMMonitoringFromInterface(CInterfaceInfo* pInterfaceInfo,IID* pInheritedInterface,BSTR* pInheritedInterFaceName,SIZE_T InheritedInterFaceMaxVTBLIndex,TCHAR* OutputDirectory);
    BOOL GenerateCOMTypeLibraryMonitoringW(WCHAR* TypeLibraryPath,TCHAR* OutputDirectory,HANDLE hCancelEvent);
    IID GetInheritedInterface(ITypeInfo* pTypeInfo,OUT BSTR* pInheritedInterFaceName, OUT SIZE_T* pInheritedInterfaceMaxVTBLIndex);
};